﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[RequireComponent(typeof(Camera))]
public class CameraController : MonoBehaviour
{

    [SerializeField]
    float rotationSpeed = 5f;
    [SerializeField]
    float moveSpeed = 0.5f;
    //[SerializeField]
    //float moveSpeedZ = 1;

    Camera CurrentCamera
    {
        get
        {
            return GetComponent<Camera>();
        }
    }

    // Update is called once per frame
    void Update()
    {
        if(Input.GetMouseButton(1))
        {
            Quaternion CurrentRotation = transform.rotation;
            float xDelta = Input.GetAxis("Mouse X");
            float yDelta = -Input.GetAxis("Mouse Y");
            CurrentRotation = Quaternion.AngleAxis(xDelta * rotationSpeed, Vector3.Dot(transform.up,Vector3.up) >= 0 ? Vector3.up : Vector3.down)  
                * CurrentRotation * Quaternion.AngleAxis(yDelta * rotationSpeed, Vector3.right);
            transform.rotation = CurrentRotation;
        }

        Vector3 CurrentPosition = transform.position;
        float xMoveDelta = Input.GetAxis("Horizontal");
        float yMoveDelta = Input.GetAxis("Vertical");
        //float zMoveDelta = Input.GetAxis("Mouse ScrollWheel");
        CurrentPosition += transform.right * xMoveDelta * moveSpeed;
        CurrentPosition += transform.forward * yMoveDelta * moveSpeed;
        //CurrentPosition += transform.forward * zMoveDelta * moveSpeedZ;

        transform.position = CurrentPosition;
    }
}
